<?php if(!defined('APP_ROOT')){exit('error!');}?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $site_title;?></title>
<link type="text/css" href="<?php echo PUBLIC_URL;?>css/font-awesome.min.css" rel="stylesheet">
<link type="text/css" href="<?php echo TEMPLATE_URL;?>style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo PUBLIC_URL;?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo TEMPLATE_URL;?>js/manage.js"></script>
</head>
<body>
<?php include View::getView('header');?>
<?php include View::getView('side');?>
<div id="mainbox">
    <div class="wrapper">
        <div class="main">
            <div class="itembox w100">
                <div class="wrap">
                    <h2><?php echo $page_title;?></h2>
                    <div class="itemmain">
                        <div id="adm_user">
                            <table width="100%" cellpadding="0" cellspacing="0" class="adm_table">
                                <tr>
                                    <th>用户名</th>
                                    <th>用户组</th>
                                    <th>真实姓名</th>
                                    <th>电话号码</th>
                                    <th>邮箱</th>
                                    <th>备注</th>
                                    <th width="150">操作</th>
                                </tr>
                                <?php if(!empty($users)):?>
                                <?php foreach($users as $user):?>
                                <tr>
                                    <td class="c"><a href="<?php echo APP_URL.'user/edit?uid='.$user['uid'];?>"><?php echo $user['username'];?></a></td>
                                    <td class="c"><?php echo $user['role'];?></td>
                                    <td class="c"><?php echo $user['nickname'];?></td>
                                    <td class="c"><?php echo $user['phone'];?></td>
                                    <td class="c"><?php echo $user['email'];?></td>
                                    <td class="c"><?php echo $user['description'];?></td>
                                    <td class="c">
                                        <span class="operate"><a href="<?php echo APP_URL.'user/edit?uid='.$user['uid'];?>">编辑</a></span> 
                                        <span class="operate delete"><a href="javascript:void(0);" onclick="delUser(<?php echo $user['uid'];?>)">删除</a></span>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                                <?php else:?>
                                <tr>
                                    <td colspan="6">无用户</td>
                                </tr>
                                <?php endif;?>
                            </table>
                            <div class="bottom">
                                <a href="<?php echo APP_URL.'user/edit';?>">添加用户</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php include View::getView('footer');?>
    </div>
</div>
<script type="text/javascript">
function delUser(uid){
    if(!confirm("确定删除uid为【"+uid+"】的用户吗？")){
        return false;
    }
    var token = '<?php echo loginAuth::genToken();?>';
    $.ajax({
        'type':'post',
        'dataType':'json',
        'url':'<?php echo APP_URL;?>user/handle',
        'data':'uid='+uid+'&token='+token+"&action=del",
        'success':function(data){
            alert(data.msg);
            if(data.result==200){
                location.reload();
            }
        }
    });
    return false;
}
</script>
</body>
</html>